﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;

namespace UnitShared
{
    public class UnitTemplate
    {
        public struct AbilityUses
        {
            public int Id;
            public int Uses;
        }

        string texture;

        string name;
        string faction;
        string description;
        string types;
        int pointCost;
        int hp;
        int speed;
        int attack;
        int magic;
        int defense;
        int magicDefense;
        List<AbilityUses> abilities;
        string movementType;

        #region Properties

        public string Texture
        {
            get
            {
                return texture;
            }
            set
            {
                texture = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }

        public string Faction
        {
            get
            {
                return faction;
            }
            set
            {
                faction = value;
            }
        }

        public string Description
        {
            get
            {
                return description;
            }
            set
            {
                description = value;
            }
        }

        public string Types
        {
            get
            {
                return types;
            }
            set
            {
                types = value;
            }
        }

        public int PointCost
        {
            get
            {
                return pointCost;
            }
            set
            {
                pointCost = value;
            }
        }

        public int Hp
        {
            get
            {
                return hp;
            }
            set
            {
                hp = value;
            }
        }

        public int Speed
        {
            get
            {
                return speed;
            }
            set
            {
                speed = value;
            }
        }

        public int Attack
        {
            get
            {
                return attack;
            }
            set
            {
                attack = value;
            }
        }

        public int Magic
        {
            get
            {
                return magic;
            }
            set
            {
                magic = value;
            }
        }

        public int Defense
        {
            get
            {
                return defense;
            }
            set
            {
                defense = value;
            }
        }

        public int MagicDefense
        {
            get
            {
                return magicDefense;
            }
            set
            {
                magicDefense = value;
            }
        }

        public List<UnitTemplate.AbilityUses> Abilities
        {
            get
            {
                return abilities;
            }
            set
            {
                abilities = value;
            }
        }

        public string MovementType
        {
            get
            {
                return movementType;
            }
            set
            {
                movementType = value;
            }
        }

        #endregion

        public UnitTemplate Clone()
        {
            UnitTemplate clone = new UnitTemplate();

            clone.texture = "Units/Art/" + this.texture;
            clone.name = this.name;
            clone.faction = this.faction;
            clone.types = this.types;
            clone.description = this.description;
            clone.pointCost = this.pointCost;
            clone.hp = this.hp;
            clone.speed = this.speed;
            clone.attack = this.attack;
            clone.magic = this.magic;
            clone.defense = this.defense;
            clone.magicDefense = this.magicDefense;
            clone.abilities = this.abilities;
            clone.movementType = this.movementType;

            return clone;
        }
    }

    public class UnitContentReader : ContentTypeReader<UnitTemplate>
    {
        protected override UnitTemplate Read(ContentReader input, UnitTemplate existingInstance)
        {
            UnitTemplate unit = new UnitTemplate();

            unit.Texture = input.ReadString();
            unit.Name = input.ReadString();
            unit.Faction = input.ReadString();
            unit.Description = input.ReadString();
            unit.Types = input.ReadString();
            unit.PointCost = input.ReadInt32();
            unit.Hp = input.ReadInt32();
            unit.Speed = input.ReadInt32();
            unit.Attack = input.ReadInt32();
            unit.Magic = input.ReadInt32();
            unit.Defense = input.ReadInt32();
            unit.MagicDefense = input.ReadInt32();
            unit.Abilities = input.ReadObject<List<UnitTemplate.AbilityUses>>();
            unit.MovementType = input.ReadString();

            return unit;
        }
    }
}
